package com.stable.actor.remotedemo;

import com.stable.actor.core.StableActor;
import com.stable.actor.network.ServiceResponse;
import lombok.extern.slf4j.Slf4j;
/**
 * 通知服务Actor
 */
@Slf4j
public class NotificationServiceActor extends StableActor {

    public NotificationServiceActor() {
        super();
    }

    @Override
    protected void setupMessageHandlers() {

    }

    @Override
    public void handleMessage(Object message) {
        if (message instanceof NotificationRequest) {
            NotificationRequest request = (NotificationRequest) message;
            log.info("📢 通知服务发送: 用户=" + request.getUserId() + ", 内容=" + request.getMessage());

            try {
                Thread.sleep(300); // 模拟处理时间

                // 通知服务通常总是成功
                ServiceResponse response = new ServiceResponse("notification", true,
                        "通知已发送给用户: " + request.getUserId());
                getSender().tell(response, getSelf());

            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                getSender().tell(new ServiceResponse("notification", false, "通知发送被中断"), getSelf());
            }
        }
    }

    @Override
    protected void preStart() {
        log.info("🚀 通知服务启动完成");
    }


}
